<script src="web/assets/plugins/jquery-validation/js/jquery.validate.min.js" type="text/javascript"></script>
<script src="web/assets/plugins/bootstrap-select2/select2.min.js" type="text/javascript"></script>
<script src="web/assets/plugins/jquery-datatable/js/jquery.dataTables.min.js" type="text/javascript" ></script>
<script src="web/assets/js/table_configuracion.js" type="text/javascript"></script>
<div class="clearfix"></div>
<div class="content">  


    <!-- Modal -->
    <div class="modal fade" id="myModalEncuestaADD" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <br>
                    <i class="icon-credit-card icon-7x"></i>
                    <h4 id="myModalLabel" class="semi-bold">Encuesta</h4>
                    <p class="no-margin"> </p>
                    <br>
                </div>

                <div class="modal-body">
                    <form  action="./fuentes/controller/Encuesta.php" id="formEncuesta" name="formEncuesta" autocomplete="off" > 
                          <?php require_once '/FormEncuesta.php'; ?>
                    </form>    
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->
    </div>

    <div class="row" id="respuestaView">
        <div class="col-md-12">
            <div class="grid simple ">
                <div class="grid-title no-border">
                    <h4><span class="semi-bold">Listado de Encuestas</span></h4>
                    <button style="float: right;" class="btn btn-success btn-xs " id="agregar" data-toggle="modal"  data-target="#myModalEncuestaADD"> Agregar</button>
                    <div class="labelRight" id="error">	

                    </div>
                </div>
                <div class="grid-body no-border">

                    <table class="table table-hover no-more-tables table-condensed  " id="encuestaTABLE">
                        <thead>
                            <tr>
                                <th style="width:1%" >ID</th>
                                <th style="width:10%">TITULO</th>
                                <th style="width:20%">PREGUNTA</th>
                                <th class='text-center' style="width:2%">ORDEN</th>
                                <th class='text-center' style="width:2%">GRUPO</th>
                                <th class='text-center' style="width:5%">PROMEDIO</th>
                                <th class='text-center'  style="width:10%">ACCION</th>
                            </tr>
                        </thead>
                        <tbody id="encuestaList">

                            <?php

                            if ($encuestas) {
                                foreach ($encuestas as $dato) {
                                    $porcentaje = consultar("SELECT  COUNT(r.id) as cantidad , SUM(r.valoracion) as sumatoria_valoracion 
                                        FROM respuestas as r where r.encuesta_id=" . $dato["id"]);
                                    $p = 0;
                                    if ($porcentaje) {
                                        $valor = strval($porcentaje[0]['sumatoria_valoracion']);
                                        $cantidad = strval($porcentaje[0]['cantidad']);

                                        if ($valor == null) {
                                            $p = (0);
                                        } else {
                                            $p = (($valor * 100) / ($cantidad * 5));
                                        }

                                        $color = "";
                                        if ($p <= 25) {
                                            $color = "progress-bar-danger";
                                        } else if ($p <= 50) {
                                            $color = "progress-bar-warning";
                                        } else if ($p <= 75) {
                                            $color = "progress-bar-info";
                                        } else if ($p <= 100) {
                                            $color = "progress-bar-success";
                                        }
                                    }
//                                    $valor=strval($porcentaje[0]['sumatoria_valoracion']);
//                                    var_dump($porcentaje);
//                                    $cantidad=strval($porcentaje[0]['cantidad']);
//                                    var_dump($porcentaje[0]['cantidad']);
//                                    $p=(($valor*100)/($cantidad*5));

                                    echo "<tr >";
                                    echo "<td>";
                                    echo $dato["id"];
                                    echo "</td>";


                                    echo "<td>";
                                    echo $dato["titulo"];
                                    echo "</td>";
                                    echo "<td>";
                                    echo $dato["pregunta"];
                                    echo "</td>";

                                    echo "<td class='text-center' >";
                                    echo $dato["orden"];
                                    echo "</td>";

                                    echo "<td class='text-center' >";
                                    echo $dato["grupo"];
                                    echo "</td>";

                                    echo "<td class='text-center'  >";
                                    echo "<div class='progress'>
                                                <div data-percentage='0%' style='width: " . $p . "%;'  class='progress-bar " . $color . "' role='progressbar' aria-valuemin='0' aria-valuemax='100'></div>
                                             </div>";
                                    echo "</td>";

                                    echo "<td  >";
                                    echo "<button class='btn btn-success btn-xs btn-mini' onclick='editDatos(" . $dato["id"] . ")'  title='Editar' ><i class='fa fa-pencil'></i></button>";
                                    echo "&nbsp; ";
                                    echo "<button class='btn btn-success btn-xs btn-mini' onclick='eliminarDato(" . $dato["id"] . ")' title='Eliminar' ><i class='fa fa-times'></i></button>";
                                    echo "&nbsp; ";
                                    echo "<button class='btn btn-success btn-xs btn-mini' onclick='respuesta(" . $dato["id"] . ")' title='Respuestas' ><i class='fa fa-random'></i></button>";

                                    echo "</td>";
                                    echo " </tr>";
                                }
                            } 
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="./fuentes/view/encuesta/js/script_ajax_encuesta.js" type="text/javascript"></script>

